package com.start.platform.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.core.annotations.RegisterMenu;
import com.start.core.annotations.RegisterPermission;
import com.start.core.annotations.StartLog;
import com.start.platform.core.entity.StartPlatformUserEntity;
import com.start.platform.core.service.StartPlatformUserService;
import com.start.security.annotations.DataPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 第三方平台用户信息
 *
 * @author gxl
 * @email ${email}
 * @date 2021-03-25 09:12:51
 */
@RestController
@RequestMapping("/start/platform/user" )
@RegisterMenu(value = "第三方平台用户信息",parentId="fa082311783863635318d8e0ed424554", systemCode = "start:platform:user", component = "views/start/platform/user/index", path = "/start/platform/user/index" )
public class StartPlatformUserController {
    private static final String LOG_TITLE = "第三方平台用户信息";

    @Autowired
    private StartPlatformUserService platformUserService;

    /**
     * 列表
     */
    @GetMapping("/page" )
    @DataPermission("start/platform/user/list" )
    public Result<?> list(Page<StartPlatformUserEntity> page, StartPlatformUserEntity entity) {
        QueryWrapper<StartPlatformUserEntity> queryWrapper = DataQueryConstructor.createEntity(entity);
        return Result.ok(platformUserService.page(page, queryWrapper));
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}" )
    @StartLog(value = LOG_TITLE, action = "查询" )
    @PreAuthorize("@pas.hasPermission('start:platform:user:info')" )
    @RegisterPermission(value = "start:platform:user:info", name = "查看" )
    public Result<?> info(@PathVariable("id" ) String id) {
        return Result.ok(platformUserService.getById(id));
    }

    /**
     * 保存
     */
    @PostMapping("/add" )
    @StartLog(value = LOG_TITLE, action = "添加" )
    @PreAuthorize("@pas.hasPermission('start:platform:user:add')" )
    @RegisterPermission(value = "start:platform:user:add", name = "添加" )
    public Result<?> save(@RequestBody StartPlatformUserEntity thirdPartyPlatformFans) {
            platformUserService.save(thirdPartyPlatformFans);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/updateById" )
    @StartLog(value = LOG_TITLE, action = "修改" )
    @PreAuthorize("@pas.hasPermission('start:platform:user:edit')" )
    @RegisterPermission(value = "start:platform:user:edit", name = "修改" )
    public Result<?> update(@RequestBody StartPlatformUserEntity thirdPartyPlatformFans) {
            platformUserService.updateById(thirdPartyPlatformFans);
        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteById/{id}" )
    @StartLog(value = LOG_TITLE, action = "删除" )
    @PreAuthorize("@pas.hasPermission('start:platform:user:delete')" )
    @RegisterPermission(value = "start:platform:user:delete", name = "删除" )
    public Result<?> delete(@PathVariable("id" ) String id) {
            platformUserService.removeById(id);
        return Result.ok();
    }

}
